<template>
  <div class="item-box">
    <block-header icon="/static/icon/haoyou.png" title="通讯录好友" :load="loadAll" :number="num"></block-header>
    <friends-list :data="friendsDataTemp" v-if="friendsDataTemp.length > 0"></friends-list>
    <span v-else class="tip-null">暂无数据</span>
  </div>
</template>

<script>
  import BlockHeader from '../../components/block-header'
  import FriendsList from '../../components/friends-list'
  import request from '../../helper/request'

  export default {
    name: 'friends-block',
    components: {
      BlockHeader,
      FriendsList
    },
    mixins: [],
    computed: {},
    props: {
      data: {
        type: Object,
        default() {
          return {}
        }
      }
    },
    data() {
      return {
        friendsData: [],
        friendsDataTemp: [],
        num: ''
      }
    },
    methods: {
      /**
       * 查看全部
       */
      loadAll() {
        this.$store.commit('updatePhone', this.data)
        this.$router.push('/friends-block-all')
      },
      getQueryList(limit = 5) {
        let param = Object.assign({
          'sjh': '',
          'pageObj': {
            'currPage': 1,
            'pageSize': limit,
            'pagination': '1'
          }
        }, this.data)
        request('superRecord/mobile/txlhy', 'SC0425', param).then(res => {
          this.num = res.pageResult.totalCount
          this.friendsData = res.txlhy.map(resHY => {
            let _realName = resHY.sm.map(rsm => {
              return {
                name: rsm.xm,
                num: rsm.num
              }
            })
            let _identity = resHY.zssf.map(rzssf => {
              return {
                name: rzssf.xm,
                idcard: rzssf.sfzh,
                lab: rzssf.bs
              }
            })
            return {
              tableName: resHY.tableName,
              systemid: resHY.systemid,
              name: resHY.hyxm,
              phone: resHY.sjhm,
              callNumber: resHY.tlcs,
              lastTime: resHY.zhtlsj,
              realName: _realName,
              identity: _identity
            }
          })
          this.friendsDataTemp = this.friendsData.slice(0, 2)
        }).catch(err => {
          this.$toast(err.msg)
        })
      }
    },
    watch: {},
    mounted() {
    },
    created() {
      this.getQueryList()
    }
  }
</script>

<style scoped>

</style>
